package jdbc;

import java.sql.*;

public class JBDCDemo8 {
    public static void main(String[] args) {
        //预编译sql
        try (Connection conn = DBUtil.getConnection()){
            LoginUserInfo loginUserInfo = InputUtil.getInputObject(new LoginUserInfo(),"欢饮回来宝贝~");
            Statement statement = conn.createStatement();
            String sql = "SELECT username,nickname,password,age FROM userinfo WHERE username = ? AND password = ?;";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, loginUserInfo.getUsername());
            ps.setString(2, loginUserInfo.getPassword());
            ResultSet rs = ps.executeQuery();
            if (rs.next()){
                String nickname = rs.getString("nickname");
                System.out.println("欢迎回来，"+nickname);
            }else{
                System.out.println("登陆失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
